﻿using System;
using System.Web;

namespace CY_MVC.Core
{
    internal static class SeoHelper
    {
        public const string SeoManagerTitleKey = "CY_MVC.HtmlParser.SEOHelper_PageTitle_";
        public const string SeoManagerKeywordsKey = "CY_MVC.HtmlParser.SEOHelper_PageKeywords_";
        public const string SeoManagerDescriptionKey = "CY_MVC.HtmlParser.SEOHelper_PageDescription_";

        internal static string Generate(string p_ViewStr)
        {
            var SEOstr = string.Empty;

            if (HttpContext.Current.Items.Contains(SeoManagerTitleKey))
            {
                SEOstr += "<title>" + HttpContext.Current.Items[SeoManagerTitleKey] + "</title>" + Environment.NewLine;
            }

            if (HttpContext.Current.Items.Contains(SeoManagerKeywordsKey))
            {
                SEOstr += "<meta name=\"keywords\" content=\"" + HttpContext.Current.Items[SeoManagerKeywordsKey] + "\" />" + Environment.NewLine;
            }

            if (HttpContext.Current.Items.Contains(SeoManagerDescriptionKey))
            {
                SEOstr += "<meta name=\"description\" content=\"" + HttpContext.Current.Items[SeoManagerDescriptionKey] + "\" />" + Environment.NewLine;
            }
            if (!string.IsNullOrEmpty(SEOstr))
            {
                p_ViewStr = p_ViewStr.Replace("<head>", "<head>" + SEOstr);
            }

            return p_ViewStr;
        }
    }
}
